// Created from GroupGenerationTemplate
// For Decisions HL7 Engine
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using DecisionsFramework.Design.Properties;
using Decisions.HL7.DataTypes;
using ST = System.String;
using SI = System.String;
using IS = System.String;
using ID = System.String;
using SNM = System.String;

namespace Decisions.HL7.Message
{
    [DataContract]
	public class TIMING_BRT_O32 : AbstractGroup
    {
        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("11 TQ1",11)]
  	    [HL7Field(HL7Version.v25, 11, HL7Repeat.False, HL7Required.True,"TQ1")]
	    public TQ1 TQ1 {get;set;}

        /// -----------------------------
        /// -----------------------------
		[DataMember]
	    [PropertyClassification("12 TQ2",12)]
  	    [HL7Field(HL7Version.v25, 12, HL7Repeat.True, HL7Required.False,"TQ2")]
	    public TQ2[] TQ2 {get;set;}



		#region Parser Helpers and Conrete Impls

        internal override void ConsumeTextSegmentsForGroup(Stack<string> availableData, HL7ParserOptions options) {

			TQ1 = PopSegmentParseAndCheckRequired<TQ1>(availableData, options, "TQ1");
			TQ2 = PopSegmentParseAndCheckRequiredArray<TQ2>(availableData, options, "TQ2");
        }

		internal override bool CanConsume(string availableData, HL7ParserOptions options)
        {
			bool isTQ1 = availableData.StartsWith("TQ1", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("TQ1", options.Version) || isTQ1) {
				return isTQ1;
			}
			bool isTQ2 = availableData.StartsWith("TQ2", StringComparison.OrdinalIgnoreCase);
			if (IsRequired("TQ2", options.Version) || isTQ2) {
				return isTQ2;
			}
			return false;
        }

        private static Dictionary<string, bool> SEGMENT_VERSION_REQUIRED_MAP = new Dictionary<string, bool>();

		protected override Dictionary<string, bool> MAP_OF_SEGMENT_TO_REQUIRED
        {
            get
			{
				return SEGMENT_VERSION_REQUIRED_MAP;
			}
        }

		public override string HL7ENTITY_TYPE_NAME
        {
            get {
				return "TIMING";
			}
        }

        static TIMING_BRT_O32() {

             SetupStaticPropertyMap(SEGMENT_VERSION_REQUIRED_MAP, typeof(TIMING_BRT_O32));

        }

		#endregion

		public override string GetER7(HL7ParserOptions options)
		{
			List<string> segmentData = new List<string>();
		 if (TQ1 != null) {
			string segmentValue = TQ1.GetER7(options);
			if (string.IsNullOrEmpty(segmentValue) == false) {
				segmentData.Add(segmentValue);
			}
		 }
		 if (TQ2 != null && TQ2.Length > 0) {
			for (int i = 0; i < TQ2.Length; i++) {
				string segmentValue = TQ2[i].GetER7(options);
				if (string.IsNullOrEmpty(segmentValue) == false) {
					segmentData.Add(segmentValue);
				}
			}
		 }
           return string.Join(HL7ParserConstants.SEGMENT_SEPARATOR, segmentData.ToArray());
        
        }
    }
}

